package com.xiaoqi.ClentCount;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Rookie Coder
 * @Description 创建一个全局域map集合放所有人的ip以及ip所开启的会话
 * @Date
 **/
public class MyServeltContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        // 創建一個Mao，key為ip，value為该ip所发出的会话对象
        Map<String, List<HttpSession>> map = new HashMap<>();
        // 获取ServletContext对象，即全局域对象
        ServletContext servletContext = sce.getServletContext();
        // 将map放入到全局域中
        servletContext.setAttribute("map", map);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
